package com.mlz.mapper;

import com.mlz.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    /**
     * 员工信息查询
     * @return 查询结果集合
     */
    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);


    //批量删除
    void delete(List<Integer> ids);


    //新增员工
    @Insert("insert into emp(username,password,name,gender,image,job,entrydate,dept_id,create_time,update_time) " +
            "values (#{username},#{password},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    //根据id查询员工信息
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp where id = #{id}")
    public Emp findById(Integer id);


    //修改员工信息
    public void update(Emp emp);


    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp where username=#{username} and password=#{password}")
    Emp getUsernameAndPassword(Emp emp);


    /**
     * 根据部门id删除部门下所有的员工
     * @param id 部门id
     */
    @Delete("delete from emp where dept_id=#{deptId}")
    void deleteByDeptId(Integer deptId);
}
